package com.mes.controller.manu;

import com.mes.service.manu.DiyListService;
import com.yy.base.common.action.BaseCtrl;
import com.yy.base.page.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("DiyList")
public class DiyListController extends BaseCtrl {
	@Autowired
	private DiyListService diyListService;

	//根据传过来的RFID带出明细信息
	@ResponseBody
	@RequestMapping(value="getDiyLists", method=RequestMethod.POST)
	public Message getVehicleLists(HttpServletRequest request) {
		Message msg = new Message();

		try{
			String code = request.getParameter("PhotoCode").toString();   //矢量图编码

			msg.setData("DiyPhotolist",diyListService.getPhotoLists(code));

			List<Map<String, Object>> hicleList = diyListService.getPhotoLists(code);

			String exeID = hicleList.get(0).get("EXEIDS").toString();

			String stauts = hicleList.get(0).get("STATUSS").toString();

			String zystauts = hicleList.get(0).get("ZYSTATUS").toString();

			String ending = "";

			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			Date time  =sdf.parse(sdf.format(new Date())); //获取当前系统时间
			if(stauts.equals("FINISHED")){
				if(zystauts.equals("CREATE")){
					ending = "START";
					diyListService.UpdateExeBeginStatus(exeID,ending);
				}else if(zystauts.equals("START")){
					ending = "FINISHED";
					diyListService.UpdateExeEndStatus(exeID,ending);
				}

			}
		}catch (Exception e){
			e.printStackTrace();
		}

		return msg;
	}

}